package com.zhijian.medical.controller;

import com.zhijian.medical.entity.dto.PersonDto;
import com.zhijian.medical.entity.po.RoutinePatientDiagnose;
import com.zhijian.medical.entity.po.RoutinePatientDiagnoseDisease;
import com.zhijian.medical.entity.po.RoutinePatientDiagnoseExtend;
import com.zhijian.medical.entity.po.RoutinePatientDiagnoseHz;
import com.zhijian.medical.entity.vo.request.RoutinePatientSearchVo;
import com.zhijian.medical.entity.vo.response.RoutinePatientDiagnoseVo;
import com.zhijian.medical.entity.vo.response.RoutinePatientVo;
import com.zhijian.medical.entity.vo.response.RoutineSingleSampleVo;
import com.zhijian.medical.holder.CurrentUserHolder;
import com.zhijian.medical.service.*;
import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Controller
@Api(tags = "常规病理-诊断")
public class RoutinePatientDiagnoseController {

    @Autowired
    RoutinePatientDiagnoseService routinePatientDiagnoseService;

    @Autowired
    RoutinePatientDiagnoseExtendService routinePatientDiagnoseExtendService;

    @Autowired
    RoutinePatientDiagnoseHzService routinePatientDiagnoseHzService;

    @Autowired
    RoutinePatientDiagnoseDiseaseService routinePatientDiagnoseDiseaseService;

    @Autowired
    RoutineSingleSampleService singleSampleService;

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/routine/patient/diagnose/page")
    @ApiOperation("分页查询")
    public Page<RoutinePatientVo> selectByCondition(@RequestBody(required = false) RoutinePatientSearchVo param) {
        if (param == null)
            param = RoutinePatientSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return routinePatientDiagnoseService.selectPage(param);
    }

    @Response
    @GetMapping("/routine/patient/diagnose/{conventionPathologyNumber}")
    @ApiOperation("诊断详情查询")
    public RoutinePatientDiagnoseVo selectOne(@PathVariable("conventionPathologyNumber") String conventionPathologyNumber){
        RoutinePatientDiagnoseVo data = routinePatientDiagnoseService.selectOne(conventionPathologyNumber);
        return data;
    }

    @Response
    @GetMapping("/routine/patient/diagnose/lk/{conventionPathologyNumber}")
    @ApiOperation("根据病理号获取蜡块号")
    public List<String> selectLknum(@PathVariable("conventionPathologyNumber") String conventionPathologyNumber){
        return singleSampleService.selectNumList(conventionPathologyNumber);
    }

    @Response
    @PostMapping("/routine/patient/diagnose")
    @ApiOperation("新增诊断")
    public RoutinePatientDiagnose addDiagnose(@RequestBody RoutinePatientDiagnose param) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return routinePatientDiagnoseService.addDiagnose(param);
    }

    @Response
    @PutMapping("/routine/patient/diagnose")
    @ApiOperation("修改诊断")
    public RoutinePatientDiagnose updateDiagnose(@RequestBody RoutinePatientDiagnose param) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return routinePatientDiagnoseService.addDiagnose(param);
    }

    @Response
    @PutMapping("/routine/patient/diagnose/audit/{id}")
    @ApiOperation("审核报告")
    public void auditDiagnose(@PathVariable("id") Long id) {
        log.info("{} - {}| audit info", this.getClass().getSimpleName(), id);
        routinePatientDiagnoseService.auditDiagnose(id);
    }

    @Response
    @PutMapping("/routine/patient/diagnose/send/audit/{id}/{auditUserId}")
    @ApiOperation("发送审核")
    public void sendAuditDiagnose(@PathVariable("id") Long id, @PathVariable("auditUserId") Long auditUserId) {
        log.info("{} - {}| audit info", this.getClass().getSimpleName(), id);
        routinePatientDiagnoseService.auditDiagnose(id, auditUserId);
    }

    @Response
    @PostMapping("/routine/patient/diagnose/extend")
    @ApiOperation("新增诊断补充报告")
    public RoutinePatientDiagnoseExtend addDiagnoseExtend(@RequestBody RoutinePatientDiagnoseExtend param) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return routinePatientDiagnoseExtendService.handleExtend(param);
    }

    @Response
    @PutMapping("/routine/patient/diagnose/extend")
    @ApiOperation("修改诊断补充报告")
    public RoutinePatientDiagnoseExtend updateDiagnoseExtend(@RequestBody RoutinePatientDiagnoseExtend param) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return routinePatientDiagnoseExtendService.handleExtend(param);
    }

    @Response
    @GetMapping("/routine/patient/diagnose/extend/{diagnoseId}")
    @ApiOperation("获取补充报告数据")
    public RoutinePatientDiagnoseExtend readDiagnoseExtend(@PathVariable("diagnoseId") Long diagnoseId) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), diagnoseId);
        return routinePatientDiagnoseExtendService.readExtendInfo(diagnoseId);
    }

    @Response
    @PutMapping("/routine/patient/diagnose/extend/{diagnoseId}")
    @ApiOperation("审核补充报告数据")
    public RoutinePatientDiagnoseExtend auditDiagnoseExtend(@PathVariable("diagnoseId") Long diagnoseId, @RequestBody(required = false) RoutinePatientDiagnoseExtend param){
        return routinePatientDiagnoseExtendService.auditExtendInfo(diagnoseId);
    }

    @Response
    @PostMapping("/routine/patient/diagnose/collect")
    @ApiOperation("新增诊断收藏")
    public RoutinePatientDiagnose.DiseaseCollect addDiagnoseCollect(@RequestBody RoutinePatientDiagnose.DiseaseCollect param) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return routinePatientDiagnoseService.addCollect(param);
    }

    @Response
    @PostMapping("/routine/patient/diagnose/hz")
    @ApiOperation("发送会诊医生")
    public RoutinePatientDiagnoseHz addHz(@RequestBody RoutinePatientDiagnose.HzDockerInfo hzDockerInfo){
        return routinePatientDiagnoseHzService.addHz(hzDockerInfo);
    }

    @Response
    @PutMapping("/routine/patient/diagnose/hz")
    @ApiOperation("会诊医生修改会诊结果")
    public RoutinePatientDiagnoseHz updateHz(@RequestBody RoutinePatientDiagnoseHz hzInfo){
        return routinePatientDiagnoseHzService.updateHz(hzInfo);
    }

    @Response
    @GetMapping("/routine/patient/diagnose/hz/{patientId}")
    @ApiOperation("获取报告的会诊详情")
    public RoutinePatientDiagnoseHz readOne(@PathVariable("patientId") Long patientId){
        return routinePatientDiagnoseHzService.readOne(patientId);
    }

    @Response
    @GetMapping("/routine/patient/diagnose/latest/{patientId}")
    @ApiOperation("设置最新诊断查看")
    public void latestAccount(@PathVariable("patientId") Long patientId){
        routinePatientDiagnoseService.updateLatestTime(patientId);
    }

    @Response
    @GetMapping("/routine/patient/diagnose/latest")
    @ApiOperation("最近查询")
    public Page<RoutinePatientVo> latestPage(){
        PersonDto personDto = CurrentUserHolder.getUser();
        RoutinePatientSearchVo routinePatientSearchVo = RoutinePatientSearchVo.builder().userId(personDto.getId()).build();
        return routinePatientDiagnoseService.selectLatestPage(routinePatientSearchVo);
    }

    @Response
    @PostMapping("/routine/patient/diagnose/disease")
    @ApiOperation("新增收藏疾病")
    public RoutinePatientDiagnoseDisease addDisease(@RequestBody RoutinePatientDiagnoseDisease routinePatientDiagnoseDisease){
        PersonDto personDto = CurrentUserHolder.getUser();
        routinePatientDiagnoseDisease.setUserId(personDto.getId());
        return routinePatientDiagnoseDiseaseService.addDisease(routinePatientDiagnoseDisease);
    }

    @Response
    @GetMapping("/routine/patient/diagnose/disease")
    @ApiOperation("收藏疾病查询")
    public List<RoutinePatientDiagnoseDisease> readDiseaseList(@ApiParam("查询类型。0 只查询疾病 1 查询疾病加上收藏的报告") Integer type){
        RoutinePatientDiagnoseDisease routinePatientDiagnoseDisease = new RoutinePatientDiagnoseDisease();
        PersonDto personDto = CurrentUserHolder.getUser();
        routinePatientDiagnoseDisease.setUserId(personDto.getId());
        return routinePatientDiagnoseDiseaseService.readDiseaseList(routinePatientDiagnoseDisease, type);
    }

    @Response
    @GetMapping("/routine/patient/diagnose/statics")
    @ApiOperation("相关统计数据")
    public RoutinePatientDiagnoseVo.StatisticsInfo staticsAbout(){
        RoutinePatientSearchVo searchVo = new RoutinePatientSearchVo();
        PersonDto personDto = CurrentUserHolder.getUser();
        searchVo.setUserId(personDto.getId());
        return routinePatientDiagnoseService.statics(searchVo);
    }

    @Response
    @PostMapping("/routine/patient/diagnose/qc")
    @ApiOperation("取材详情列表")
    public Page<RoutineSingleSampleVo> readSingleSampleList(@RequestBody RoutinePatientSearchVo routinePatientSearchVo){
        return routinePatientDiagnoseService.readSingleSampleList(routinePatientSearchVo);
    }

}
